/*
 *  .h
 *  
 *
 *  Created by Toan Nguyen on 5/30/12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "VCPlugInHeaders.h"

// Interface includes:
#include "IDialogMgr.h"
#include "IDialog.h"
#include "IApplication.h"
#include "ILinkObject.h"

// General includes:
#include "UIDList.h"
#include "CoreResTypes.h"
#include "LocaleSetting.h"
#include "RsrcSpec.h"


// Framework includes:
#include "AMPID.h"
#include "SnpRunnable.h"
#include "AMGlobal.h"
#include "AMPDocument.h"
#include "StringUtils.h"
#include "IIDMLComponentName.h"

#include <iostream>
using namespace std;


// --------------------------------- SnippetRunner framework hooks ---------------------------------------------------

/** Makes the snippet SnpHandleGraphicFrame available to the SnippetRunner framework.
 
 @ingroup sdk_snippet_run
 
 */
class _SnpRunnerSelectionFrame : public SnpRunnable
	{
	public:
		// For SnippetRunner framework.
		
		/** Constructor.
		 */
		_SnpRunnerSelectionFrame();
		
		/** Destructor
		 */
		virtual ~_SnpRunnerSelectionFrame();
		
		/** Return kTrue if the snippet can run.
		 @param runnableContext see ISnpRunnableContext for documentation.
		 @return kTrue if a document is open, kFalse otherwise
		 */
		bool16			CanRun(ISnpRunnableContext* runnableContext);
		
		/** Run the snippet.
		 @param runnableContext see ISnpRunnableContext for documentation.
		 @return kSuccess on success, other ErrorCode otherwise.
		 */
		ErrorCode		Run(ISnpRunnableContext* runnableContext);	
		
		/** Don't present this snippet in the framework's UI if the
		 product we are running under is InCopy. 
		 @return kFalse if the host product is InCopy, kTrue otherwise.
		 */
		bool16 CanLoad() const;
		
		/** 
		 get the snippet context
		 @return eSnpRunContextType for this snippet
		 */
		virtual ISnipRunSuite::eSnpRunContextType GetContext(void){return ISnipRunSuite::kSnpRunLayoutTargetContext;}
	};

/* Constructor
 */
_SnpRunnerSelectionFrame::_SnpRunnerSelectionFrame() : SnpRunnable("SelectionFrame")
{
	this->SetDescription("inspects graphic and text frame");
	this->SetPreconditions("make sure page item should be selected");
	this->SetCategories("sdk_snippet, sdk_graphic");
}

/* Destructor
 */
_SnpRunnerSelectionFrame::~_SnpRunnerSelectionFrame()
{
}

/*
 */
bool16 _SnpRunnerSelectionFrame::CanRun(ISnpRunnableContext* runnableContext)
{
	bool16 result = kFalse;
	printf("hahahahahaahahahahahahaah\n");
	// Require a layout selection to be able to run.
	InterfacePtr<ILayoutTarget> layoutTarget(runnableContext, UseDefaultIID());
	if (layoutTarget != nil) {
		UIDList itemList = layoutTarget->GetUIDList(kStripStandoffs);
		if (itemList.Length() > 0) {
			result = kTrue;
		}
	}
	
	return result;
}

/* 
 */
ErrorCode _SnpRunnerSelectionFrame::Run(ISnpRunnableContext* runnableContext)
{
	ErrorCode status = kSuccess;
	return status;
}

/* 
 */
bool16  _SnpRunnerSelectionFrame::CanLoad() const
{
	bool16 result = kTrue;
	if (LocaleSetting::GetLocale().IsProductFS(kInCopyProductFS)) {
		// Graphic attributes can be applied to page items under InCopy
		// but we don't load this snippet because there's no pointer tool 
		// to select a page item with. If we loaded the snippet the Go 
		// button for the snippet would mostly be disabled.
		result = kFalse;
	}
	return result;
}

/*	Declare an instance to register the snippet hook with the framework.
 */
static _SnpRunnerSelectionFrame instance_SnpRunnerSelectionFrame;
DEFINE_SNIPPET(_SnpRunnerSelectionFrame)
//End, SnpHandleGraphicFrame.cpp
